<template>
  <div class="mutation-project" :class="{ 'read-only': readOnly }">
    <div class="mutation-it">
      <div
        :class="item.class"
        v-for="(item, i) in tableList.column"
        :key="i"
      >
        <div class="item-mutation" v-if="!item.hide && (!item.depend || mutationObj[item.depend] === true)">
          <span v-if="!item.table">
            <span></span>
            <span>{{ item.title }}</span>
          </span>
          <el-date-picker
            clear-icon
            type="datetime"
            v-model="mutationObj[item.field]"
            v-if="item.type == 'date'"
            class="dates"
          />
          <el-select 
            v-model="mutationObj[item.field]" 
              v-else-if="item.select"
             placeholder="请选择">
            <el-option
              v-for="item2 in item.select"
              :key="item2.value"
              :label="item2.name"
              :value="item2.value">
            </el-option>
          </el-select>
          <div class="table-it" v-else-if="item.table">
            <span class="table-title">
              {{ item.title }}
            </span>
            <span class="notes">
              {{ item.notes }}
            </span>
            <el-button
              class="add-button"
              type="warning"
              @click="mutationObj[item.field].push({})"
            >
              {{ item.table.btn }}
            </el-button>
            <ul class="ul-list">
              <li>
                <span style="width: 10%" class="names">序号</span>
                <span style="width: 35%" class="names"
                  >股东身份证或营业执照号码</span
                >
                <span style="width: 15%" class="shares">股权比例（%）</span>
                <span style="width: 15%" class="shares">出资额（万元）</span>
                <span style="width: 20%" class="option" v-if="!readOnly">
                  操作
                </span>
              </li>
              <li v-for="(item2, i) in mutationObj[item.field]" :key="i">
                <span style="width: 10%">
                  {{ i + 1 }}
                </span>
                <span style="width: 35%">
                  <el-input
                    type="text"
                    v-model="item2.sfz"
                    placeholder="股东身份证或营业执照号码"
                  />
                </span>
                <span style="width: 15%">
                  <el-input
                    type="number"
                    v-model="item2.gqbl"
                    placeholder="股权比例"
                    class="short-input"
                  />
                </span>
                <span style="width: 15%">
                  {{ item2.cze || 0 }}
                </span>
                <span style="width: 20%" class="option" v-if="!readOnly">
                  <el-button
                    type="danger"
                    @click="mutationObj[item.field].splice(i, 1)"
                  >
                    删除
                  </el-button>
                </span>
              </li>
            </ul>
          </div>
            <el-upload
              class="upload-wrapper"
              action="https://jsonplaceholder.typicode.com/posts/"
              multiple
              :limit="3"
              v-else-if="item.file"
              :file-list="fileList">
              <el-button type="primary" size="medium" plain icon="el-icon-upload">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          <!-- @uploaded="uploaded" -->
          <el-input
            type="text"
            v-model="mutationObj[item.field]"
            v-else
            :placeholder="item.title"
          />
          <span class="notes" v-if="item.notes && !item.table">{{
            item.notes
          }}</span>
        </div>
      </div>
      <div class="btn-conf" v-if="!readOnly">
        <el-button type="primary" @click="editInfo">修改</el-button>
        <el-button type="primary" @click="saveInfo">提交</el-button>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible="saveModal.open"
      width="30%"
    >
      <span>确认提交？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="saveModal.open = false">取 消</el-button>
        <el-button type="primary" @click="saveMutation">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
export default {
  props: ["tableList", "readOnly"],
  name: "mutation",
  data() {
    return {
      mutationObj: {
        gqbl: []
      },
      saveModal: {
        open: false
      },
      selectObj: {},
      fileList: []
    };
  },
  filters: {
    formatDate(time) {
      const date = new Date(time);
      return `${date.getFullYear()}年${date.getMonth() +
        1}月${date.getDate()}日`;
    }
  },
  mounted() {
    const self = this;
    self.init();
  },
  methods: {
    async infoInit() {
      let vm = this;
      vm.dateConfig = dateConfig;
    },
    init() {
      let vm = this;
      vm.tableList.column.forEach(item => {
        if (item.table) {
          vm.mutationObj[item.field] = [{ id: 1 }];
        }
      });
    },
    editInfo() {},
    saveInfo() {
      this.saveModal.open = true;
    },
    saveMutation() {
      this.$emit("confirm");
      this.saveModal.open = false;
    }
  }
};
</script>

<style lang="less" scoped>
.item-mutation{
}
  .btn-conf {
    display: block;
    margin: 80px 0 0 35%;
  }
  .add-button{
    float: right;
  }
  .ul-list{
    .el-input{
      width: 100%;
    }
  }
</style>
